home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / ov143b.zip / OVFMOVE.C < prev    next >
C/C++ Source or Header  |  1993-01-04  |  9KB  |  271 lines

  1. /*  027  18-Apr-87  ovfmove.c
  2.  
  3.         Copyright (c) 1987 by Blue Sky Software.  All rights reserved.
  4. */
  5.  
  6. #include <stdio.h>
  7. #include "ov.h"
  8. #include "direct.h"
  9.  
  10. /* The following define will effect the speed of some screen updates - for
  11.    the PC set it to 1 - make it higher for slower terminals with hardware
  12.    (firmware?) scrolling */
  13.  
  14. #define SCROLL_LIMIT 1         /* #lines to update b 4 just rewritting screen */
  15.  
  16. extern WINDOW cw;
  17. extern FILE_ENT files[];
  18.  
  19.  
  20. /******************************************************************************
  21.  **                           M O V E _ F I L E                              **
  22.  *****************************************************************************/
  23.  
  24. move_file(move_cmd)    /* move the file pointer around, scroll if needed */
  25. register int move_cmd;
  26. {
  27.  
  28.    register int dif;
  29.    int currow, scrolled = FALSE;
  30.    int last_idx, wrap_factor, redisplayed = FALSE;
  31.  
  32.    if (cw.nfiles == 0)                 /* don't even try if no files in dir */
  33.       return;
  34.  
  35.    if (move_cmd == PGUP || move_cmd == PGDN) { /* special case PgUp & PgDn */
  36.       pagedisp(move_cmd);                      /* all done by pagedisp() */
  37.       return;
  38.     }
  39.  
  40.    last_idx = cw.curidx;               /* remember where we were */
  41.  
  42.    wrap_factor = (cw.nrows * cw.ncols) - 1;  /* used for right/left wrap */
  43.  
  44.    /* translate left/right movement to up/down if only 1 column displayed */
  45.  
  46.    if (cw.ncols == 1)
  47.       move_cmd = move_cmd == RIGHT ? DOWN : (move_cmd == LEFT ? UP : move_cmd);
  48.  
  49.    switch (move_cmd) {
  50.  
  51.       case LEFT:                       /* left arrow */
  52.          cw.curidx -= cw.nrows;
  53.          if (cw.curidx < 0) {
  54.             cw.curidx += wrap_factor;
  55.             while (cw.curidx >= cw.nfiles)
  56.                cw.curidx -= cw.nrows;
  57.             if (cw.curidx == cw.nfiles - cw.nrows - 1)
  58.                cw.curidx += cw.nrows;
  59.           }
  60.           break;
  61.  
  62.       case RIGHT:                      /* right arrow */
  63.          cw.curidx += cw.nrows;
  64.          if (cw.curidx >= cw.nfiles) {
  65.             cw.curidx -= wrap_factor;
  66.             while (cw.curidx < 0)
  67.                cw.curidx += cw.nrows;
  68.             if (cw.curidx == cw.nrows)
  69.                cw.curidx = 0;
  70.          }
  71.          break;
  72.  
  73.       case UP:                         /* up arrow */
  74.          cw.curidx--;
  75.          if (cw.curidx < 0)
  76.             cw.curidx = cw.nfiles-1;
  77.          break;
  78.  
  79.       case DOWN:                       /* down arrow */
  80.          cw.curidx++;
  81.          if (cw.curidx >= cw.nfiles)
  82.             cw.curidx = 0;
  83.          break;
  84.  
  85.       case HOME:                       /* home key */
  86.          cw.curidx = 0;
  87.          break;
  88.  
  89.       case END:                        /* end key */
  90.          cw.curidx = cw.nfiles - 1;
  91.          break;
  92.    }
  93.  
  94.    /* scroll or redisplay the screen if the current position is not displayed */
  95.  
  96.    if (!on_screen(cw.curidx)) {        /* screen need to be adjusted? */
  97.  
  98.       /* if the display needs to be adjusted by less than SCROLL_LIMIT
  99.          rows in the display area, use the scroll routines, otherwise
  100.          just redisplay using new nbase value */
  101.  
  102.       currow = idx2lr(cw.curidx);      /* needed several times below */
  103.  
  104.       dif = (currow < cw.nbase) ? currow - cw.nbase :
  105.                                   currow - cw.nbase - cw.ndrows + 1;
  106.  
  107.       if (abs(dif) <= SCROLL_LIMIT) {    /* scroll? */
  108.  
  109.          fp_off(last_idx);               /* this way, ptr doesn't move */
  110.  
  111.          if (dif > 0)
  112.             while (dif--)
  113.                scroll_dn();
  114.          else
  115.             while (dif++)
  116.                scroll_up();
  117.          scrolled = TRUE;                 /* saves a call to fp_on() */
  118.  
  119.       } else {                            /* redisplay screen */
  120.  
  121.          adjust_window();                 /* recalc cw.nbase, etc */
  122.          update_window(1);                /* redisplay file names */
  123.          redisplayed = TRUE;              /* avoid extra fp_*() calls */
  124.       }
  125.    }
  126.  
  127.    /* deselect the last item if the file pointer has moved and the last
  128.       item is still displayed (and the screen wasn't adjusted) */
  129.  
  130.    if (!redisplayed && !scrolled && cw.curidx != last_idx &&
  131.        on_screen(last_idx))
  132.       fp_off(last_idx);
  133.  
  134.    /* highlight the current file if the file pointer moved and the screen
  135.       wasn't adjusted (adjustments set the pointer) */
  136.  
  137.    if (!redisplayed && !scrolled && cw.curidx != last_idx)
  138.       fp_on(cw.curidx);
  139. }
  140.  
  141.  
  142. /*****************************************************************************
  143.                                P A G E D I S P
  144.  *****************************************************************************/
  145.  
  146. static int
  147. pagedisp(dir)          /* page the file display indicated direction */
  148. int dir;
  149. {
  150.    int newidx;
  151.    register int newnbase = cw.nbase;
  152.  
  153.    if (dir == PGUP) {                  /* page up a screen? */
  154.  
  155.       newnbase -= cw.ndrows;           /* backup a screen */
  156.  
  157.    } else {                            /* must want to page down */
  158.  
  159.       newnbase += cw.ndrows;
  160.       if (newnbase + cw.ndrows > cw.nrows)  /* don't leave part of the  */
  161.          newnbase = cw.nrows - cw.ndrows;   /*   screen blank if avoidable */
  162.    }
  163.  
  164.    if (newnbase < 0)                   /* adjustments can go too far */
  165.       newnbase = 0;
  166.  
  167.    if (newnbase == cw.nbase) {         /* is the page the same? */
  168.       if (dir == PGUP)                 /* up direction? */
  169.          newidx = newnbase;            /* yes, goto top to page */
  170.       else
  171.          newidx = cw.nfiles - 1;       /* no, goto last file */
  172.       fp_off(cw.curidx);               /* move file pointer */
  173.       fp_on(cw.curidx = newidx);
  174.  
  175.    } else {            /* the page base changed, redisplay window */
  176.  
  177.       cw.nbase = newnbase;             /*  this is the one to use now      */
  178.       if (!on_screen(cw.curidx))       /*  will the old current file show? */
  179.          cw.curidx = newnbase;         /*  if not, we know this one will   */
  180.       update_window(1);                /*  display names at new offset     */
  181.    }
  182. }
  183.  
  184.  
  185. /******************************************************************************
  186.                         F P _ O N / O F F
  187.  *****************************************************************************/
  188.  
  189. int ALTCALL
  190. fp_on(i)               /* turn on the file pointer */
  191. register int i;
  192. {
  193.    gotorc(idx2sr(i),idx2sc(i));
  194.    disp_file(&files[i],1);
  195.    if (cw.showall)
  196.       disp_path(i);
  197. }
  198.  
  199. int ALTCALL
  200. fp_off(i)              /* turn off the file pointer */
  201. register int i;
  202. {
  203.    gotorc(idx2sr(i),idx2sc(i));
  204.    disp_file(&files[i],0);
  205. }
  206.  
  207.  
  208. /******************************************************************************
  209.                             O N _ S C R E E N
  210.  *****************************************************************************/
  211.  
  212. int ALTCALL
  213. on_screen(idx)         /* determine if file[idx] is currently displayed */
  214. register int idx;
  215. {
  216.    /* this used to be a macro, but it generates a lot of code */
  217.  
  218.    return(idx2lr(idx) >= idx2lr(cw.nbase) &&
  219.           idx2lr(idx) <= min(cw.nrows-1,idx2lr(cw.nbase)+cw.ndrows-1));
  220. }
  221.  
  222.  
  223. /******************************************************************************
  224.  **                    S C R O L L _ U P                                     **
  225.  *****************************************************************************/
  226.  
  227. static int
  228. scroll_up() {          /* scroll the file display up */
  229.  
  230.    register int m;
  231.  
  232.    cw.nbase -= 1;
  233.    insert_line(cw.fnrow+1,cw.ndrows-1);
  234.  
  235.    gotorc(cw.fnrow,0);                 /* cursor to first display position */
  236.  
  237.    /* display a row of file names */
  238.  
  239.    for (m = cw.nbase; m < cw.nfiles; m += cw.nrows)
  240.       disp_file(&files[m],m == cw.curidx);
  241.  
  242.    if (cw.showall)
  243.       disp_path(cw.curidx);
  244. }
  245.  
  246.  
  247. /******************************************************************************
  248.  **                    S C R O L L _ D N                                     **
  249.  *****************************************************************************/
  250.  
  251. static int
  252. scroll_dn() {          /* scroll the file display down */
  253.  
  254.    register int m;
  255.  
  256.    cw.nbase += 1;
  257.    delete_line(cw.fnrow,cw.ndrows-1);
  258.  
  259.    gotorc(cw.fnrow+cw.ndrows-1,0);     /* cursor to the last display line */
  260.  
  261.    /* display a row of file names */
  262.  
  263.    for (m = cw.nbase + cw.ndrows - 1; m < cw.nfiles; m += cw.nrows)
  264.       disp_file(&files[m],m == cw.curidx);
  265.  
  266.    if (cw.showall)
  267.       disp_path(cw.curidx);
  268. }
  269.  
  270.  
  271.